package com.acme.bankapp.service.bank.client;

import com.acme.bankapp.service.bank.network.Transport;

import java.io.IOException;
import java.net.Socket;

public class BankClient {

    public BankClient() {
    }

    public static void main(final String args[]) {
        BankClient client = new BankClient();
        client.run("localhost", 2004, new String[]{"add accounttype=c;balance=300;overdraft=70;name=NewClient;gender=m;", "get clients_balance", "bye"});
    }

    public void run(String host, int port, String[] commands) {
        try (Socket socket = new Socket(host, port);
             Transport transport = new Transport(socket)
        ) {
            for (String command : commands) {
                System.out.println("client>" + command);
                transport.sendMessage(command);
                String answer = transport.receiveMessage();
                System.out.println("server>" + answer);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
